gdk: Make backends implement move_to_rect()
authorJonas Ådahl <jadahl@gmail.com>
Mon, 15 Jul 2019 09:35:24 +0000 (11:35 +0200)
committerJonas Ådahl <jadahl@gmail.com>
Thu, 25 Jul 2019 08:24:50 +0000 (10:24 +0200)
The generic layer still does the heavy lifting, leaving the backends
more or less just act as thin wrappers, dealing a bit with global
coordinate transformations. The end goal is to remove explicit surface
moving from the generic gdk layer.

gdk/broadway/gdksurface-broadway.c
gdk/gdksurface.c
gdk/gdksurfaceprivate.h
gdk/quartz/gdksurface-quartz.c
gdk/win32/gdksurface-win32.c
gdk/x11/gdksurface-x11.c

index d3da0740303e7ed8fd503b446e7a717a3f00f5b2..90f14563c5c9fa987f60733d4133c81a81c7b0f1 100644 (file)
@@ -440,6 +440,55 @@ gdk_broadway_surface_move (GdkSurface *surface,
   gdk_broadway_surface_move_resize (surface, TRUE, x, y, -1, -1);
 }
 
+static void
+gdk_broadway_surface_moved_to_rect (GdkSurface   *surface,
+                                    GdkRectangle  final_rect)
+{
+  GdkSurface *toplevel;
+  int x, y;
+
+  if (surface->surface_type == GDK_SURFACE_POPUP)
+    toplevel = surface->parent;
+  else
+    toplevel = surface->transient_for;
+
+  gdk_surface_get_origin (toplevel, &x, &y);
+  x += final_rect.x;
+  y += final_rect.y;
+
+  if (final_rect.width != surface->width ||
+      final_rect.height != surface->height)
+    {
+      gdk_broadway_surface_move_resize (surface,
+                                        TRUE,
+                                        x, y,
+                                        final_rect.width, final_rect.height);
+    }
+  else
+    {
+      gdk_broadway_surface_move (surface, x, y);
+    }
+}
+
+static void
+gdk_broadway_surface_move_to_rect (GdkSurface         *surface,
+                                   const GdkRectangle *rect,
+                                   GdkGravity          rect_anchor,
+                                   GdkGravity          surface_anchor,
+                                   GdkAnchorHints      anchor_hints,
+                                   gint                rect_anchor_dx,
+                                   gint                rect_anchor_dy)
+{
+  gdk_surface_move_to_rect_helper (surface,
+                                   rect,
+                                   rect_anchor,
+                                   surface_anchor,
+                                   anchor_hints,
+                                   rect_anchor_dx,
+                                   rect_anchor_dy,
+                                   gdk_broadway_surface_moved_to_rect);
+}
+
 static void
 gdk_broadway_surface_raise (GdkSurface *surface)
 {
@@ -1329,6 +1378,7 @@ gdk_broadway_surface_class_init (GdkBroadwaySurfaceClass *klass)
   impl_class->restack_toplevel = gdk_broadway_surface_restack_toplevel;
   impl_class->move_resize = gdk_broadway_surface_move_resize;
   impl_class->toplevel_resize = gdk_broadway_surface_toplevel_resize;
+  impl_class->move_to_rect = gdk_broadway_surface_move_to_rect;
   impl_class->get_geometry = gdk_broadway_surface_get_geometry;
   impl_class->get_root_coords = gdk_broadway_surface_get_root_coords;
   impl_class->get_device_state = gdk_broadway_surface_get_device_state;
index e5c41e68c441eda9ffd1e7aa72aafa494f6d8483..8c52953972bb8f3bcfdac2771377c79929d99343 100644 (file)
@@ -253,14 +253,15 @@ maybe_flip_position (gint      bounds_pos,
   return primary;
 }
 
-static void
-gdk_surface_real_move_to_rect (GdkSurface         *surface,
-                               const GdkRectangle *rect,
-                               GdkGravity          rect_anchor,
-                               GdkGravity          surface_anchor,
-                               GdkAnchorHints      anchor_hints,
-                               gint                rect_anchor_dx,
-                               gint                rect_anchor_dy)
+void
+gdk_surface_move_to_rect_helper (GdkSurface            *surface,
+                                 const GdkRectangle    *rect,
+                                 GdkGravity             rect_anchor,
+                                 GdkGravity             surface_anchor,
+                                 GdkAnchorHints         anchor_hints,
+                                 gint                   rect_anchor_dx,
+                                 gint                   rect_anchor_dy,
+                                 GdkSurfaceMovedToRect  moved_to_rect)
 {
   GdkSurface *toplevel;
   GdkDisplay *display;
@@ -369,17 +370,14 @@ gdk_surface_real_move_to_rect (GdkSurface         *surface,
   final_rect.width += surface->shadow_left + surface->shadow_right;
   final_rect.height += surface->shadow_top + surface->shadow_bottom;
 
-  if (final_rect.width != surface->width || final_rect.height != surface->height)
-    gdk_surface_move_resize (surface, final_rect.x, final_rect.y, final_rect.width, final_rect.height);
-  else
-    gdk_surface_move_resize_internal (surface, TRUE, final_rect.x, final_rect.y, -1, -1);
-
   gdk_surface_get_origin (toplevel, &x, &y);
   final_rect.x -= x;
   final_rect.y -= y;
   flipped_rect.x -= x;
   flipped_rect.y -= y;
 
+  moved_to_rect (surface, final_rect);
+
   g_signal_emit_by_name (surface,
                          "moved-to-rect",
                          &flipped_rect,
@@ -418,7 +416,6 @@ gdk_surface_class_init (GdkSurfaceClass *klass)
   object_class->get_property = gdk_surface_get_property;
 
   klass->beep = gdk_surface_real_beep;
-  klass->move_to_rect = gdk_surface_real_move_to_rect;
 
   /**
    * GdkSurface:cursor:
index eb7702f09b4295e2e87f086d3fb040363231c45e..c6d9134ffcea36b762c1fb1bd184a4ea7a3e81fc 100644 (file)
@@ -261,6 +261,19 @@ struct _GdkSurfaceClass
 void gdk_surface_set_state (GdkSurface      *surface,
                             GdkSurfaceState  new_state);
 
+typedef void (* GdkSurfaceMovedToRect) (GdkSurface   *surface,
+                                        GdkRectangle  final_rect);
+
+void
+gdk_surface_move_to_rect_helper (GdkSurface            *surface,
+                                 const GdkRectangle    *rect,
+                                 GdkGravity             rect_anchor,
+                                 GdkGravity             surface_anchor,
+                                 GdkAnchorHints         anchor_hints,
+                                 gint                   rect_anchor_dx,
+                                 gint                   rect_anchor_dy,
+                                 GdkSurfaceMovedToRect  moved_to_rect);
+
 G_END_DECLS
 
 #endif /* __GDK_SURFACE_PRIVATE_H__ */
index f77dc3f9bd15806f23b0124d4770a312a57d732b..5d7240a52fce28aee47f46a8f1f75439619f441e 100644 (file)
@@ -1263,6 +1263,54 @@ gdk_surface_quartz_toplevel_resize (GdkSurface *surface,
   window_quartz_resize (window, width, height);
 }
 
+static void
+gdk_quartz_surface_moved_to_rect (GdkSurface   *surface,
+                                  GdkRectangle  final_rect)
+{
+  GdkSurface *toplevel;
+  int x, y;
+
+  if (surface->surface_type == GDK_SURFACE_POPUP)
+    toplevel = surface->parent;
+  else
+    toplevel = surface->transient_for;
+
+  gdk_surface_get_origin (toplevel, &x, &y);
+  x += final_rect.x;
+  y += final_rect.y;
+
+  if (final_rect.width != surface->width ||
+      final_rect.height != surface->height)
+    {
+      window_quartz_move_resize (surface,
+                                 x, y,
+                                 final_rect.width, final_rect.height);
+    }
+  else
+    {
+      window_quartz_resize (surface, final_rect.width, final_rect.height);
+    }
+}
+
+static void
+gdk_quartz_surface_move_to_rect (GdkSurface         *surface,
+                                 const GdkRectangle *rect,
+                                 GdkGravity          rect_anchor,
+                                 GdkGravity          surface_anchor,
+                                 GdkAnchorHints      anchor_hints,
+                                 gint                rect_anchor_dx,
+                                 gint                rect_anchor_dy)
+{
+  gdk_surface_move_to_rect_helper (surface,
+                                   rect,
+                                   rect_anchor,
+                                   surface_anchor,
+                                   anchor_hints,
+                                   rect_anchor_dx,
+                                   rect_anchor_dy,
+                                   gdk_quartz_surface_moved_to_rect);
+}
+
 /* Get the toplevel ordering from NSApp and update our own list. We do
  * this on demand since the NSApp’s list is not up to date directly
  * after we get windowDidBecomeMain.
@@ -2651,6 +2699,7 @@ gdk_surface_impl_quartz_class_init (GdkSurfaceImplQuartzClass *klass)
   impl_class->restack_toplevel = gdk_surface_quartz_restack_toplevel;
   impl_class->move_resize = gdk_surface_quartz_move_resize;
   impl_class->toplevel_resize = gdk_surface_quartz_toplevel_resize;
+  impl_class->move_to_rect = gdk_surface_quartz_move_to_rect;
   impl_class->get_geometry = gdk_surface_quartz_get_geometry;
   impl_class->get_root_coords = gdk_surface_quartz_get_root_coords;
   impl_class->get_device_state = gdk_surface_quartz_get_device_state;
index 32d853b8d7c1bf69ec31fbe1fbb5bb72c612b697..b6b739ba9a63eb8a6601b6f994e43f8568f0ca5f 100644 (file)
@@ -1278,6 +1278,55 @@ gdk_win32_surface_move (GdkSurface *surface,
   gdk_win32_surface_move_resize (surface, TRUE, x, y, -1, -1);
 }
 
+static void
+gdk_win32_surface_moved_to_rect (GdkSurface   *surface,
+                                 GdkRectangle  final_rect)
+{
+  GdkSurface *toplevel;
+  int x, y;
+
+  if (surface->surface_type == GDK_SURFACE_POPUP)
+    toplevel = surface->parent;
+  else
+    toplevel = surface->transient_for;
+
+  gdk_surface_get_origin (toplevel, &x, &y);
+  x += final_rect.x;
+  y += final_rect.y;
+
+  if (final_rect.width != surface->width ||
+      final_rect.height != surface->height)
+    {
+      gdk_win32_surface_move_resize (surface,
+                                     TRUE,
+                                     x, y,
+                                     final_rect.width, final_rect.height);
+    }
+  else
+    {
+      gdk_win32_surface_move (surface, x, y);
+    }
+}
+
+static void
+gdk_win32_surface_move_to_rect (GdkSurface         *surface,
+                                const GdkRectangle *rect,
+                                GdkGravity          rect_anchor,
+                                GdkGravity          surface_anchor,
+                                GdkAnchorHints      anchor_hints,
+                                gint                rect_anchor_dx,
+                                gint                rect_anchor_dy)
+{
+  gdk_surface_move_to_rect_helper (surface,
+                                   rect,
+                                   rect_anchor,
+                                   surface_anchor,
+                                   anchor_hints,
+                                   rect_anchor_dx,
+                                   rect_anchor_dy,
+                                   gdk_win32_surface_moved_to_rect);
+}
+
 static void
 gdk_win32_surface_raise (GdkSurface *window)
 {
@@ -5100,6 +5149,7 @@ gdk_win32_surface_class_init (GdkWin32SurfaceClass *klass)
   impl_class->restack_toplevel = gdk_win32_surface_restack_toplevel;
   impl_class->move_resize = gdk_win32_surface_move_resize;
   impl_class->toplevel_resize = gdk_win32_surface_toplevel_resize;
+  impl_class->move_to_rect = gdk_win32_surface_move_to_rect;
   impl_class->get_geometry = gdk_win32_surface_get_geometry;
   impl_class->get_device_state = gdk_surface_win32_get_device_state;
   impl_class->get_root_coords = gdk_win32_surface_get_root_coords;
index 1ad97c2f7fd1842d1a4d0eecf228088f226b478d..690b72faaf16865129df0a24887f3d19a6086dff 100644 (file)
@@ -1408,6 +1408,55 @@ gdk_x11_surface_move (GdkSurface *surface,
   gdk_x11_surface_move_resize (surface, TRUE, x, y, -1, -1);
 }
 
+static void
+gdk_x11_surface_moved_to_rect (GdkSurface   *surface,
+                               GdkRectangle  final_rect)
+{
+  GdkSurface *toplevel;
+  int x, y;
+
+  if (surface->surface_type == GDK_SURFACE_POPUP)
+    toplevel = surface->parent;
+  else
+    toplevel = surface->transient_for;
+
+  gdk_surface_get_origin (toplevel, &x, &y);
+  x += final_rect.x;
+  y += final_rect.y;
+
+  if (final_rect.width != surface->width ||
+      final_rect.height != surface->height)
+    {
+      gdk_x11_surface_move_resize (surface,
+                                   TRUE,
+                                   x, y,
+                                   final_rect.width, final_rect.height);
+    }
+  else
+    {
+      gdk_x11_surface_move (surface, x, y);
+    }
+}
+
+static void
+gdk_x11_surface_move_to_rect (GdkSurface         *surface,
+                              const GdkRectangle *rect,
+                              GdkGravity          rect_anchor,
+                              GdkGravity          surface_anchor,
+                              GdkAnchorHints      anchor_hints,
+                              gint                rect_anchor_dx,
+                              gint                rect_anchor_dy)
+{
+  gdk_surface_move_to_rect_helper (surface,
+                                   rect,
+                                   rect_anchor,
+                                   surface_anchor,
+                                   anchor_hints,
+                                   rect_anchor_dx,
+                                   rect_anchor_dy,
+                                   gdk_x11_surface_moved_to_rect);
+}
+
 static void gdk_x11_surface_restack_toplevel (GdkSurface *surface,
                                               GdkSurface *sibling,
                                               gboolean    above);
@@ -4607,6 +4656,7 @@ gdk_x11_surface_class_init (GdkX11SurfaceClass *klass)
   impl_class->restack_toplevel = gdk_x11_surface_restack_toplevel;
   impl_class->move_resize = gdk_x11_surface_move_resize;
   impl_class->toplevel_resize = gdk_x11_surface_toplevel_resize;
+  impl_class->move_to_rect = gdk_x11_surface_move_to_rect;
   impl_class->get_geometry = gdk_x11_surface_get_geometry;
   impl_class->get_root_coords = gdk_x11_surface_get_root_coords;
   impl_class->get_device_state = gdk_x11_surface_get_device_state;